<template>
  <NuxtLayout>
    <el-breadcrumb class="my-crumb">
      <el-breadcrumb-item v-for="(item, index) in crumbData" :key="index">
        <a :href="item.href">{{ item.title }}</a>
      </el-breadcrumb-item>
    </el-breadcrumb>
    <div class="con">
      <div class="con_cen">
        <div class="con_cen_left">
          <div class="con_cen_left_top">
            <img class="con_cen_left_top_icon" src="https://static.dzyxzx.cn/jkbpc/exam_logo.png" />
            <div class="con_cen_left_top_item">
              <strong>题库选择</strong>
              <p>按分类选择题库类别</p>
            </div>
          </div>
          <div class="con_cen_left_bottom">
            <ul class="con_cen_left_bottom_ul">
              <li class="con_cen_left_bottom_ul_li">
                <a v-for="item in subjectData" :key="item.id"
                  class="el-button el-button--primary el-button--small is-plain" :href="`/exercises/${item.id}`" :title="item.name">{{
                    item.name }}</a>
              </li>
            </ul>
          </div>
        </div>
        <div class="con_cen_right">
          <div class="con_cen_right_top">
            <div class="con_cen_right_top_link" @click="exercisesDetailsHrefFn()">
              <strong>模拟考试</strong>
              <span>模拟在线真实考场</span>
            </div>
            <div class="con_cen_right_top_link" @click="exercisesDetailsHrefFn()">
              <strong>精选练题</strong>
              <span>按顺序练习做题</span>
            </div>
          </div>
          <div class="con_cen_right_bottom">
            <div class="con_cen_right_bottom_link" @click="exercisesDetailsHrefFn()">
              <img class="con_cen_right_bottom_link_icon" src="https://static.dzyxzx.cn/jkbpc/exam_c.png" />
              <div class="con_cen_right_bottom_link_item">
                <strong>全部习题</strong>
                <p>共0道题</p>
              </div>
            </div>
            <!-- <div class="con_cen_right_bottom_link" @click="exercisesDetailsHrefFn()">
              <img class="con_cen_right_bottom_link_icon" src="https://static.dzyxzx.cn/jkbpc/exam_d.png" />
              <div class="con_cen_right_bottom_link_item">
                <strong>未做习题</strong>
                <p>共0道题</p>
              </div>
            </div> -->
            <div class="con_cen_right_bottom_link" @click="exercisesDetailsHrefFn()">
              <img class="con_cen_right_bottom_link_icon" src="https://static.dzyxzx.cn/jkbpc/exam_e.png" />
              <div class="con_cen_right_bottom_link_item">
                <strong>我的错题</strong>
                <p>共0道题</p>
              </div>
            </div>
          </div>
          <div class="con_cen_right_clear">
            <span class="con_cen_right_clear_link" @click="clearExamFn">清除习题记录</span>
          </div>
        </div>
      </div>
    </div>
  </NuxtLayout>
</template>

<script setup>
import { getQuestionListApi, clearExerciseRecord } from '~/server/api'
import { useCountStore } from "~/store/counter.js";
import { useToken } from '~/store/token';
useCountStore().$patch({
  indexActive: 4
});
const crumbData = ref([
  { title: '首页', href: '/' },
  { title: '题库中心', href: 'javascript:;' },
])
// TDK
const prevHost = useRequestHeaders()["x-forwarded-proto"];
const host = useRequestHeaders()["host"];
const fullPath = useRoute()["fullPath"];
useSeoMeta({
  title: "题库中心",
  keywords: "题库中心",
  description: "题库中心",
  ogTitle: "题库中心",
  ogDescription: "题库中心",
  ogType: "article",
  ogUrl: `${prevHost}://${host}${fullPath}`,
});
// 科目
const subjectData = ref([])
async function getSubject() {
  let { data: subjectRes } = await useAsyncData('getQuestionListApi', () => useServerRequest(getQuestionListApi, {
    method: 'post',
    body: JSON.stringify({
      pageNum: 1,
      pageSize: 666,
      exerciseOpen: true,
      parentId: 0
    })
  }))
  if (subjectRes.value && subjectRes.value.errno === 0 && subjectRes.value.result && subjectRes.value.result.total > 0) {
    subjectData.value = subjectRes.value.result.list;
  }
}
getSubject()
// 习题路径跳转
function exercisesDetailsHrefFn() {
  if (useToken().token) {
    ElMessage.warning('请选择课题类别')
    return false;
  }
  navigateTo('/login')
  ElMessage.error('请先登录')
}
// 清除习题记录
function clearExamFn() {
  ElMessageBox.confirm('是否清除习题记录？', '系统提示').then(async () => {
    let res = await useServerRequest(clearExerciseRecord, {
      method: 'get',
      params: {
        subjectId: ''
      }
    })
    if (res.errno === 0) {
      ElMessage.success('清除成功')
      return false
    }
  }).catch(() => {})
}
</script>

<style lang="less" scoped>
p {
  margin: 0;
}

.con {
  min-height: calc(100vh - 454px);
  padding: 20px 0;

  &_cen {
    width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;

    &_left {
      width: 300px;
      min-height: 460px;
      margin-right: 20px;
      background: #FFFFFF url('https://static.dzyxzx.cn/jkbpc/menu_b.png') 0 0 / 100% no-repeat;
      box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.03);
      border-radius: 10px;

      &_top {
        padding: 44px 0 0 25px;
        height: 156px;
        display: flex;

        &_icon {
          width: 59px;
          height: 58px;
          margin-right: 11px;
        }

        &_item {
          flex: 1;
          overflow: hidden;

          >strong {
            font-size: 26px;
            height: 26px;
            line-height: 26px;
          }

          >p {
            margin-top: 12px;
            font-size: 16px;
          }
        }
      }

      &_bottom {
        padding: 40px 25px;

        &_ul {

          &_li {
            overflow: hidden;

            .el-button {
              margin: 0 12px 12px 0;

              &+.el-button {
                margin: 0 12px 12px 0;
              }
            }
          }
        }
      }
    }

    &_right {
      flex: 1 0;
      background: #FFFFFF;
      box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.03);
      border-radius: 10px;
      padding: 50px 24px;
      min-height: 460px;

      &_top {
        display: flex;
        align-items: stretch;
        justify-content: space-between;

        &_link {
          flex: 410px 0;
          height: 100px;
          border-radius: 10px;
          padding-left: 95px;
          padding-top: 36px;
          display: flex;
          align-items: baseline;
          overflow: hidden;
          cursor: pointer;

          &:nth-child(1) {
            background: url('https://static.dzyxzx.cn/jkbpc/exam_a.png') 0 0 / 410px no-repeat;
          }

          &:nth-child(2) {
            background: url('https://static.dzyxzx.cn/jkbpc/exam_b.png') 0 0 / 410px no-repeat;
          }

          >strong {
            color: #FFFFFF;
            font-weight: bold;
            font-size: 26px;
          }

          >span {
            margin-left: 10px;
            color: #FFFFFF;
            font-size: 20px;
          }
        }
      }

      &_bottom {
        margin-top: 30px;
        display: flex;
        align-items: stretch;

        &_link {
          flex: 270px 0;
          height: 100px;
          background-color: #F5F5F5;
          border-radius: 10px;
          overflow: hidden;
          display: flex;
          align-items: center;
          padding: 20px;
          margin-right: 12px;
          cursor: pointer;

          &:last-child {
            margin-right: 0;
          }

          &_icon {
            width: 60px;
            height: 60px;
            margin-right: 14px;
          }

          &_item {
            flex: 1 0;
            overflow: hidden;

            >strong {
              font-weight: bold;
              font-size: 24px;
              height: 24px;
              line-height: 24px;
              color: #666666;
            }

            >p {
              font-size: 14px;
              height: 14px;
              line-height: 14px;
              color: #666666;
              margin-top: 9px;
            }
          }
        }
      }

      &_clear {
        text-align: center;
        margin-top: 20px;

        &_link {
          color: #999;
          font-size: 14px;
          cursor: pointer;
        }
      }
    }
  }
}
</style>